package com.admin.business.venusOaMenjin;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 门禁
 * @create: 2022-04-06 09:55:15
 **/
@Service("venusOaMenjin")
@Slf4j
public class VenusOaMenjinService{

    @Resource
    VenusOaMenjinDao venusOaMenjinDao;

    /**
     * 添加门禁,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:操作人id
     *                   - mj_code:编码
     *                   - mj_addr:MAC地址
     *                   - mj_edition:门禁版本
     *                   - mj_name:名称
     *                   - ip_addr:ip地址
     *                   - mj_factory:门禁厂家
     *                   - mj_direction:门禁方向
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return addVenusOaMenjin(CDO cdoRequest) {
        venusOaMenjinDao.addVenusOaMenjin(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新门禁数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:操作人id
     *                   - mj_code:编码
     *                   - mj_addr:MAC地址
     *                   - mj_edition:门禁版本
     *                   - mj_name:名称
     *                   - ip_addr:ip地址
     *                   - mj_factory:门禁厂家
     *                   - mj_direction:门禁方向
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return updateVenusOaMenjinById(CDO cdoRequest) {
        int affectedRows = venusOaMenjinDao.updateVenusOaMenjinById(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，删除门禁数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return deleteVenusOaMenjinById(CDO cdoRequest){
        int affectedRows = venusOaMenjinDao.deleteVenusOaMenjinById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除门禁数据
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return deleteVenusOaMenjin(CDO cdoRequest) {
        int affectedRows = venusOaMenjinDao.deleteVenusOaMenjin(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("affectedRows", affectedRows);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取门禁数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return getVenusOaMenjinById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaMenjinDao.getVenusOaMenjinById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据混合条件，获取门禁数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return getVenusOaMenjin(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaMenjinDao.getVenusOaMenjin(cdoRequest);
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取门禁数据列表
     *
     * @param cdoRequest
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return getVenusOaMenjinList(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaMenjinDao.getVenusOaMenjinList(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaMenjinDao.getVenusOaMenjinListCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据混合条件，获取门禁数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author ht
     * @create: 2022-04-06 09:55:15
     */
    @OpenApi
    public Return getVenusOaMenjinListByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaMenjinDao.getVenusOaMenjinListByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaMenjinDao.getVenusOaMenjinListByConditionCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
